//
//  ManagerHuiVC.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/4/14.
//  Copyright © 2017年 金橙云. All rights reserved.
//
#define O_WIDTH [UIScreen mainScreen].bounds.size.width
#import "ManagerHuiVC.h"

#import "MYouHuiCell.h"
#import "MZengJiaVC.h"
#import "TodoHttpManager.h"
#import "MYouHuiXVC.h"
@interface ManagerHuiVC ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *tabView;
@property(nonatomic,strong)NSMutableArray *youArr;
@end

@implementation ManagerHuiVC

-(void)viewWillAppear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didTDManagerYouHuiBiao:) name:TDManagerYouHuiBiao object:nil];
    
    NSUserDefaults *userDefa = [NSUserDefaults standardUserDefaults];
    
    NSString *uid= [userDefa objectForKey:@"USER_ID"];
    NSString *IDA = [[NSUserDefaults standardUserDefaults] objectForKey:@"STATE"];
    NSLog(@"=======IDA==%@",IDA);
    [_manager userManagerYouHuiWithUserId:uid];
    
}

-(void)didTDManagerYouHuiBiao:(NSNotification *)notifi
{
    if (notifi.object != 0)
    {
        _youArr = [notifi.object objectForKey:@"data"];
        
        
        [_tabView reloadData];
        
    }
}
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:TDManagerYouHuiBiao object:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"优惠申请";
    self.view.backgroundColor =BgColor;
    _youArr = [NSMutableArray array];
    UIView *oneView = [[UIView alloc] initWithFrame:CGRectMake(0, 64, B_WIDTH, 30)];
    oneView .backgroundColor = [UIColor whiteColor];
    [self.view addSubview:oneView];

    UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithTitle:nil style:UIBarButtonItemStylePlain target:self action:@selector(zengJiaBtnClick)];
    
    self.navigationItem.rightBarButtonItem = rightBarItem;
    [self.navigationItem.rightBarButtonItem setImage:[[UIImage imageNamed:@"xinzenggenjin"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    _manager = [TodoHttpManager sharedManager];
    
    
    
    NSInteger a = 70;
    NSInteger b = (O_WIDTH-15*2-a*4)/3;
    
    UILabel *oneLab = [[UILabel alloc] init];
    oneLab.text = @"申请日期";
    oneLab.textAlignment = NSTextAlignmentCenter;
    oneLab.font = [UIFont systemFontOfSize:12];
    oneLab.textColor =[UIColor blackColor];
    [oneView addSubview:oneLab];
    [oneLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(a, 20));
        make.left.equalTo(oneView.mas_left).offset(15);
        make.top.equalTo(oneView.mas_top).offset(5);
    }];
    
    UILabel *tLab = [[UILabel alloc] init];
    tLab.text = @"客户姓名";
    tLab.textAlignment = NSTextAlignmentCenter;
    tLab.font = [UIFont systemFontOfSize:12];
    tLab.textColor =[UIColor blackColor];
    [oneView addSubview:tLab];
    [tLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(a, 20));
        make.left.equalTo(oneLab.mas_right).offset(b);
        make.top.equalTo(oneView.mas_top).offset(5);
    }];
    
    
    UILabel *sLab = [[UILabel alloc] init];
    sLab.text = @"房源位置";
    sLab.textAlignment = NSTextAlignmentCenter;
    sLab.font = [UIFont systemFontOfSize:12];
    sLab.textColor =[UIColor blackColor];
    [oneView addSubview:sLab];
    [sLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(a, 20));
        make.left.equalTo(tLab.mas_right).offset(b);
        make.top.equalTo(oneView.mas_top).offset(5);
    }];
    
    UILabel *fLab = [[UILabel alloc] init];
    fLab.text = @"审批状态";
    fLab.textAlignment = NSTextAlignmentCenter;
    fLab.font = [UIFont systemFontOfSize:12];
    fLab.textColor =[UIColor blackColor];
    [oneView addSubview:fLab];
    [fLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(a, 20));
        make.right.equalTo(oneView.mas_right).offset(-15);
        make.top.equalTo(oneView.mas_top).offset(5);
    }];

    
    _tabView = [[UITableView alloc] initWithFrame:CGRectMake(0, 96, B_WIDTH, B_HEIGHT-96) style:UITableViewStylePlain];
    _tabView.delegate = self;
    _tabView.dataSource = self;
    _tabView.rowHeight = 40;
    _tabView.backgroundColor = BgColor
    _tabView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    [self.view addSubview:_tabView];
    


}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _youArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID = @"Cell";
    MYouHuiCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell)
    {
        cell = [[MYouHuiCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    if ([cell isKindOfClass:[MYouHuiCell class]])
    {
        if (_youArr.count !=0)
        {
            NSDictionary *dict = [_youArr objectAtIndex:indexPath.row];
            [(MYouHuiCell *)cell setManagerYouHuiWithDayString:dict[@"sq_date"] withNameString:dict[@"kh_name"] withHouseString:dict[@"fy"] withShenString:dict[@"shenpi_status"] withShenLable:dict[@"sp_zt"]];
        }
        
    }

    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MYouHuiXVC *youXVC = [[MYouHuiXVC alloc] init];
    youXVC.IDStr = [[_youArr objectAtIndex:indexPath.row] objectForKey:@"id"];
    NSLog(@"=======222222======%@",  youXVC.IDStr );
    [self.navigationController pushViewController:youXVC animated:NO];
}
-(void)zengJiaBtnClick
{
    
    MZengJiaVC *mZengVC = [[MZengJiaVC alloc] init];
    [self.navigationController pushViewController:mZengVC animated:NO];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
